/**
 * 校验用户名合法性
 * @param {string} username 用户名
 */
const validateUsername = username => {
  if (username === "" || username === undefined) return false
  return true
}

/**
 * 校验密码合法性
 * @param {string} password 密码
 */
const validatePassword = password => {
  if (password === "" || password === undefined) return false
  const passwordPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
  return passwordPattern.test(password)
}

/**
 * 校验邮箱合法性
 * @param {string} email 邮箱
 */
const validateEmail = email => {
  if (email === "" || email === undefined) return false
  const emailPattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/
  return emailPattern.test(email)
}

module.exports = {
  validateUsername,
  validatePassword,
  validateEmail
}